###
 # @Author: Clark
 # @Email: haixuanwoTxh@gmail.com
 # @Date: 2021-12-01 12:10:20
 # @LastEditors: Clark
 # @LastEditTime: 2021-12-01 12:30:42
 # @Description: file content
###

# 1、if语句
if [ false ]
then
    echo "test if grammar"
elif [ true ]
then
    echo "test elif grammar"
else
    echo "test else grammar"
fi

# 2、for语句
# for var in item1 item2 ... itemN
# do
#     command1
#     command2
#     ...
#     commandN
# done

for value in 1 2 3 4 5
do
    echo "value: "$value
done

# 3、while
# while condition
# do
#     command
# done
n=1
while (( $n<=5 ))
do
    echo $n;
    let "n++"
done

# while : 无限循环
# while true
# for (( ;; ))

# 4、until语句
# until condition   与while相反，条件为真时才停止
# do
#     command
# done
m=10
until [ $m -eq 1 ]
do
    echo $m
    let "m--"
done

# 5、case ... esac
# case 值 in
# 模式1)
#     command1
#     command2
#     ...
#     commandN
#     ;;
# 模式2)
#     command1
#     command2
#     ...
#     commandN
#     ;;
# esac

echo '输入 1 到 4 之间的数字:'
echo '你输入的数字为:'
read aNum
case $aNum in
    1)
        echo '你选择了 1'
        ;;
    2)
        echo '你选择了 2'
        ;;
    3)
        echo '你选择了 3'
        ;;
    4)
        echo '你选择了 4'
        ;;
    *)
        echo '你没有输入 1 到 4 之间的数字'
        ;;
esac

# 6、break和continue
x=5
while true
do
    let "x--"
    if [ $x -eq 1 ]
    then
        echo continue:$x
        break
    else
        echo continue:$x
        continue
    fi
    echo done
done

